<?php
	require_once '../../../const.php';
	require_once '../database/mysql/MysqlUserDao.php';
	require_once '../domain/User.php';
	
	use org\kahikai\database\mysql\MysqlUserDao;
	use org\kahikai\domain\User;
	
	session_start();
	
	if(!isset($_SESSION['userDao'])) {
		$_SESSION['userDao'] = new MysqlUserDao();
	}
	
	$user = $_SESSION['userDao']->getById($_GET['id']);
	if($user != null && $user->confirmationNumber == $_GET['confirmation_number']) {
		$user->confirmationNumber = null;
		$user->profile = 'user';
		if($_SESSION['userDao']->update($user)) {
			$_SESSION['user'] = $user;
			$_SESSION['isAuthenticated'] = true;
		}
	}
	
	header("location: $ROOT_URL/kahikai");
?>